# coding=utf-8
import os
from git.repo import Repo
import datetime
import shutil
import subprocess
from flask import Flask
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


def Codezip(source, desc):
    ret = shutil.make_archive(source, 'zip', root_dir=desc)
    return ret


def shell(command):
    ret = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8",
                         timeout=1)
    if ret.returncode == 0:
        print("success:", ret)
        print("输出信息为:%s" % ret.stdout)
        return ret
    else:
        print("error:", ret)
        return ret


def runshell(file, path):
    file = os.path.splitext(file)
    filename, type = file
    if type == '.sh':
        result = ssh.command("sh %s" % path)
    else:
        result = ssh.command("python %s" % path)


